/**
 * 
 */
package us.gaaoc.framework.signature.digital;

import java.io.UnsupportedEncodingException;

import org.apache.log4j.Logger;

import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPException;
import com.novell.ldap.LDAPSearchResults;


/**
 * @author Sukahda Tapshalkar
 * Aug 18, 2006
 *
 */
public class LDAPAuthetication {
	
	private String searchBase = "DC=directory,DC=gaje,DC=us";
	private String filter = "(&(objectClass=pkiUser)(cn=Sukhada Tapshalkar))";

	private int ldapPort = LDAPConnection.DEFAULT_PORT;

	// Search all sub-trees of the base
	private int searchScope = LDAPConnection.SCOPE_SUB;
	private int ldapVersion = LDAPConnection.LDAP_V3;

	private String ldapHost = "directory.gaje.us";
	private String loginDN = "cn=Manager,DC=directory,DC=gaje,DC=us";	 
	private String loginPassword = "secret";
	
	private LDAPSearchResults searchResult = null;

	Logger LOG = Logger.getLogger(LDAPAuthetication.class);
	
	public LDAPSearchResults getSearchResults() {
		LDAPConnection ldapConnection = new LDAPConnection();

		try {
			// Connect to the server
			ldapConnection.connect(ldapHost, ldapPort);

			// bind to the server
			ldapConnection.bind(ldapVersion, loginDN, loginPassword.getBytes("UTF8"));

			// perform search
			searchResult = ldapConnection.search(searchBase, searchScope, filter, null, false);

		} catch (LDAPException e) {
			LOG.error("Error: " + e.toString(),e);
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			LOG.error("Error: " + e.toString(),e);

		}
		return searchResult;
	}
}
